package st.business.tepth.business.taskallocation;

import st.business.tepth.base.OnDataConvertListener;
import st.business.tepth.business.bean.CommonPageBean;
import st.business.tepth.business.bean.TaskAllocationBean;

/**
 * Author: shadow
 * Email:  1025431817@qq.com
 * Time:   2019-02-26 10:30
 */

public class TaskAllocationPresenter extends TaskAllocationContract.Presenter {
    private final TaskAllocationContract.View mView;
    private final TaskAllocationContract.Model mModel;

    public TaskAllocationPresenter(TaskAllocationContract.View view) {
        mView = view;
        mModel = new TaskAllocationModel();
    }

    @Override
    void getAllocationList(String token) {
        addDisposable(mModel.getAllocationList(token,
                new OnDataConvertListener<CommonPageBean<TaskAllocationBean>>() {
                    @Override
                    public void convert(CommonPageBean<TaskAllocationBean> bean) {
                        if (mView != null) {
                            mView.showAllocationList(bean.getList());
                        }
                    }

                    @Override
                    public void error(int code, String msg) {
                        if (mView != null) {
                            mView.showError(msg);
                        }
                    }
                }));
    }

    @Override
    void cancelReturn(String token, int repairId) {
        addDisposable(mModel.cancelReturn(token, repairId,
                new OnDataConvertListener<String>() {
                    @Override
                    public void convert(String s) {
                        if (mView != null) {
                            mView.cancelReturnSucceed();
                        }
                    }

                    @Override
                    public void error(int code, String msg) {
                        if (mView != null) {
                            mView.showError(msg);
                        }
                    }
                },
                new OnDataConvertListener<CommonPageBean<TaskAllocationBean>>() {
                    @Override
                    public void convert(CommonPageBean<TaskAllocationBean> bean) {
                        if (mView != null) {
                            mView.showAllocationList(bean.getList());
                        }
                    }

                    @Override
                    public void error(int code, String msg) {
                        mView.showError(msg);
                    }
                }));
    }
}
